import { defineStore } from "pinia";
import { get, post } from "@/utils/request";
import {ref} from "vue";

export const useStudentUserStore = defineStore('studentUser',() => {
  let studentUserData = ref({})
  
  // 学生信息列表数据
  const studentUserRequest = async () => {
    try{
      const response = await get('/student/info',{})
      console.log(response)
      // if(response.code == 200) {
        studentUserData.value = response.data
        console.log(studentUserData.value)
      // }
    }catch(error){
      console.error(error)
    }
  } 

  // 修改密码
  const changePasswordRequest = async (changePassword) => {
    try{
      const response = await post('/student/changepassword',{
        oldPassword:changePassword.oldPassword,
        newPassword:changePassword.newPassword,
        confirmNewPassword:changePassword.confirmNewPassword
      })
      if(response.code == 200) {

      }
    }catch(error){
      console.error(error)
    }
  }

  return {studentUserData,studentUserRequest,changePasswordRequest}
})